import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_audioplayers.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_high_input_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_picker_photo.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_picker_video.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/modules/reporting_hidden_dangers/reporting_hidden_dangers_controller.dart';

/// 隐患上报页面
class ReportingHiddenDangersPage extends StatelessWidget {
  ReportingHiddenDangersPage({super.key});

  final controller = Get.put(ReportingHiddenDangersController());

  /// 选择框
  Widget _getChoiceView(String title, String value) {
    return Column(
      children: [
        Container(
          padding: EdgeInsets.symmetric(vertical: 20.w),
          child: Row(
            children: [
              Text(
                title,
                style: TextStyle(fontSize: 14.sp, height: 1.2, color: const Color(0xFF262F38), fontWeight: FontWeight.w400),
              ),
              AppGaps.hGap50,
              Expanded(
                child: Container(
                  alignment: Alignment.centerRight,
                  child: Text(
                    value == '' ? '请选择$title' : value,
                    style: TextStyle(
                      fontSize: 14.sp, height: 1.2, color: value == '' ? const Color(0xFFA0A7B5) : const Color(0xFF666666), //const Color(0xFF262F38),
                    ),
                  ),
                ),
              ),
              AppGaps.hGap6,
              Icon(Icons.arrow_forward_ios, size: 14.sp, color: AppColors.text_grey)
            ],
          ),
        ),
        Divider(
          height: 1.w,
          color: const Color(0xffECEEF3),
        )
      ],
    );
  }

  /// 填写输入内容
  Widget _getBasisContentView() {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: Column(
        children: [
          _getChoiceView('隐患确认人', controller.arrangeEntity.confirmBy!).clickOnce(controller.selectReportingPersonnel),
          _getChoiceView('对象', controller.arrangeEntity.riskObjectName!).clickOnce(controller.selectObject),
          _getChoiceView('单元', controller.arrangeEntity.riskUnitName!).clickOnce(controller.selectUnit),
          CustomHighInputPage(
            title: '隐患描述：',
            isRequired: false,
            isShowDivider: false,
            text: controller.arrangeEntity.dangerRecordDesc,
            hintText: '请输入隐患描述',
            onCallBack: (value) {
              controller.arrangeEntity.dangerRecordDesc = value;
            },
          ),
          AppGaps.vGap20,
        ],
      ),
    );
  }

  /// 获取其他信息
  Widget _getOtherContentView() {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          CustomPickerPhoto(
            title: '拍照:',
            maxCount: 9,
            imagesList: controller.arrangeEntity.dangerImages!,
            titleTextStyle: TextStyle(
              fontSize: 14.sp,
              height: 1.2,
              fontWeight: FontWeight.w500,
              color: const Color(0xff262F38),
            ),
          ),
          Divider(
            height: 1.w,
            color: const Color(0xffECEEF3),
          ),
          CustomPickerVideo(
            title: '拍摄:',
            maxCount: 1,
            videoList: controller.arrangeEntity.dangerVideo!,
            titleTextStyle: TextStyle(
              fontSize: 14.sp,
              height: 1.2,
              fontWeight: FontWeight.w500,
              color: const Color(0xff262F38),
            ),
          ),
          Divider(
            height: 1.w,
            color: const Color(0xffECEEF3),
          ),
          AppGaps.vGap20,
          Text(
            '语音:',
            style: TextStyle(fontSize: 14.sp, height: 1.2, color: const Color(0xFF262F38), fontWeight: FontWeight.w500),
          ),
          AppGaps.vGap16,
          SvgPicture.asset(
            AppImages.icon_tape,
            width: 80.w,
            height: 80.w,
          ).clickOnce(controller.onTapTape),
          AppGaps.vGap16,
          CustomAudioplayers(
            audioUrl: controller.arrangeEntity.dangerVoice!,
            key: controller.globalKey,
            onCallBack: (List<String> urls) {
              controller.playersCallBack(urls);
            },
          ),
          SizedBox(height: 70.w)
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            appBar: CustomAppBar(
              titleText: '隐患上报',
            ),
            body: Container(
              alignment: Alignment.topCenter,
              color: const Color(0xffF5F5F6),
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    AppGaps.vGap12,
                    _getBasisContentView(),
                    AppGaps.vGap16,
                    _getOtherContentView(),
                  ],
                ),
              ),
            ),
            bottomSheet: Container(
              height: 50.w,
              alignment: Alignment.center,
              padding: EdgeInsets.symmetric(horizontal: 16.w),
              decoration: BoxDecoration(
                color: Colors.white,
                boxShadow: [
                  BoxShadow(
                    color: const Color(0xffBCBCC5).withOpacity(0.3), // 阴影颜色
                    offset: const Offset(0, -5), // 阴影的偏移量，向上偏移，即上方阴影
                    blurRadius: 10.0, // 阴影的模糊半径
                    spreadRadius: 2.0, // 阴影的扩散半径
                  ),
                ],
              ),
              child: Container(
                  height: 40.w,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                      color: const Color(0xff5C6DFF),
                      borderRadius: BorderRadius.all(
                        Radius.circular(20.w),
                      )),
                  child: Text(
                    '确定',
                    style: TextStyle(
                      fontSize: 16.sp,
                      color: const Color(0xffffffff),
                    ),
                  )).clickOnce(controller.confirm),
            ),
          );
        });
  }
}
